package com.krtech.wecard.module.ramble.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.krtech.wecard.framework.exception.BusinessException;
import com.krtech.wecard.framework.security.Inner;
import com.krtech.wecard.framework.utils.LoginUtil;
import com.krtech.wecard.module.ramble.entity.RambleLoginLog;
import com.krtech.wecard.module.ramble.service.RambleLoginLogService;
import com.krtech.wecard.module.sys.entity.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/rambleLogin")
@Slf4j
@Api(tags = "佳得乐漫步-登陆记录")
public class RambleLoginLogController {

    @Autowired
    private RambleLoginLogService rambleLoginLogService;

    @PostMapping("/loginLog")
    @ApiOperation(value = "获得步数之后就调用这个接口")
    public boolean loginLog(@RequestBody RambleLoginLog loginLog) {
        return rambleLoginLogService.loginLog(loginLog);
    }

    @GetMapping("/page")
    @ApiOperation(value = "page")
    public Page<RambleLoginLog> page(Page<RambleLoginLog> page, String keyword) {
        QueryWrapper<RambleLoginLog> wrapper = new QueryWrapper<>();
        if (StrUtil.isNotEmpty(keyword)){
            wrapper.like(RambleLoginLog.COL_PHONE,keyword);
        }
        return rambleLoginLogService.page(page,wrapper);
    }

    @GetMapping("/judgeFirstEnter")
    @ApiOperation(value = "判断是否是第一次进入,true：是第一次进入，false：不是第一次进入")
    public boolean judgeFirstEnter(){
        SysUser userInfo = LoginUtil.getUserInfo();
        int judge = rambleLoginLogService.count(new QueryWrapper<RambleLoginLog>().eq(RambleLoginLog.COL_PHONE, userInfo.getPhone()));
        if (judge > 0){
            return false;
        }
        return true;
    }

}
